package org.zhucy.zk;

import org.I0Itec.zkclient.ContentWatcher;
import org.I0Itec.zkclient.IZkDataListener;
import org.I0Itec.zkclient.ZkClient;

import java.util.List;
import java.util.Optional;


/**
 * @Auther: zhuchunyang
 * @Date: 2019/6/19 16:33
 * @Description:
 */
public class ZkDemoSub {

    private static final String ZK_SERVER = "127.0.0.1:2181";
    public static void main(String[] args) {
        ZkClient zkClient = new ZkClient(ZK_SERVER,3000);
        //zkClient.writeData("/zk_test","this is a test");
        //while(true) {
            zkClient.subscribeDataChanges("/zk_test", new IZkDataListener() {
                @Override
                public void handleDataChange(String s, Object o) throws Exception {
                    System.out.println(s);
                    System.out.println(o.toString());
                }

                @Override
                public void handleDataDeleted(String s) throws Exception {

                }
            });
        //}

    }
}
